<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript">
    $(document).ready(function() {
        var fm1 = ["form1", "child_container", "form1Id"];
        Page.createForm(fm1);
        TempUtil.render('child_template', 'form1',DOC);
        Page.setStripeTable();

        var theUpdateFileName = "";
        var $btnUpload = $('#btnUpload');
        var datas;
        $btnUpload.bind('click', function() {
            if($('#fp')[0].files[0].size > 104857600) {
                AlertUtil.alertMsg(PROMPT.status.uploadSize);
                return;
            };
            SysUtil.upload($('#form1'), $('#fp'), "system", function(fileName) {
                theUpdateFileName = fileName;
                closeBox();
            });
        });

        function update() {
            var isOk = false;
            datas = null;
            SysUtil.showProgress(ProgressTime.UPDATE_PARTIAL, PROMPT.status.updating,
                function() {
                    return datas != null || isOk;
                },
                function() {
                    if(datas == -1 || datas == -2)
                    {
                        AlertUtil.alertMsg(PROMPT.status.updateFalse);
                        location.reload();
                    }else {
                        AlertUtil.alertMsg(PROMPT.status.updateSuccess);
                        reboot();
                        location.href = Page.getUrl(Url.LOGIN);

                    }

                }
            );

        }
		
		function reboot(ip) {
            // 发送重启命令
            Page.postJSON({
                json: {
                    cmd: RequestCmd.SYS_REBOOT,
                    method: JSONMethod.POST
                },
                success: function() {
                    var isOk = false;
                    var timeoutCtl = setTimeout(function() {
                        isOk = true;
                    }, 1000 * 90);
                    SysUtil.showProgress(ProgressTime.REBOOT, PROMPT.status.rebooting,
                        function() {
                            return isOk;
                        },
                        function() {
                            clearTimeout(timeoutCtl);
                            if(ip){
                                window.location.href = window.location.href.replace(window.location.host, ip);
                            }else {
                                location.reload();
                            }

                        }
                    );
                },
                fail: function() {

                }
            });
        }


        $('#btnUpdatePartial').bind('click', function() {

            if (theUpdateFileName == "") {
                AlertUtil.alertMsg(CHECK.required.uploadFile);
                return false;
            }


            Page.postJSON({
                json: {
                    cmd: RequestCmd.UPDATE_PARTIAL,
                    method: JSONMethod.POST,
                    fileName: theUpdateFileName
                },
                success: function(data) {
                    datas = data.data;
                },
                fail: function(data) {
                    datas = data.data;
                }
            });

            update();
        });

        $('#form1').attr({
            "enctype": "multipart/form-data",
            "method": "post"
        });

    });

</script>

<div class="detail_box" id="child_container">
    <div id="form1Id">
        <script type="text/template" id="child_template">
            <div class="detail"><%- title.localUpdate %></div>
            <table class="detail" cellspacing="0">
                <tr>
                    <th><%- sys.selectUpdateFile %><%- colon %></th>
                    <td>
                        <!-- <form id="form1" enctype="multipart/form-data" method="post"> -->
                            <input type="file" id="fp" name="fp" style="display:none;" onchange=filepath.value=this.value>
                            <input type="textfield" id="filepath">
                            <input type="button" id="filebutton" value="<%- btn.browse %>" onclick="fp.click()">
                            <input type="button" id="btnUpload" value="<%- btn.upload %>"/>
                        <!-- </form> -->                  
                    </td>
                </tr>
                <tr>
                    <th>&nbsp;</th>
                    <td>
                        <input type="button" id="btnUpdatePartial" value="<%- btn.update %>" />
                    </td>
                </tr>
            </table>
        </script>
    </div>
</div>